package cn.sitedev.serial.preventserial;


import java.io.Serializable;

/**
 * @author qchen
 * @description 演示防止被序列化/反序列化造成单例被破坏
 * @date 2020/9/17 23:29
 */
public class SerializableSingleton implements Serializable {
    // 序列化: 对象=>字节数组
    // 反序列化: 字节数组=>对象

    private static final SerializableSingleton INSTANCE = new SerializableSingleton();

    private SerializableSingleton() {
    }

    public static SerializableSingleton getInstance() {
        return INSTANCE;
    }

    private Object readResolve() {
        return INSTANCE;
    }

}
